// we7/pages/index/1-1shouYeSearch2.js
const app = getApp();
Page({

  
  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: "",
    inputList:'',
    historyInpVal:"",
    StatusBar: app.globalData.StatusBar, //模态动画
    CustomBar: app.globalData.CustomBar,
    vale:""
  },
  //模态动画
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    
    this.setData({
      modalName: null
    })
  },
  
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    console.log(e)
  // 发送请求
    var that = this;
    var vale = e.detail.value
    that.setData({
      vale: vale
    })
    if (vale.indexOf(" ")>=0) {
      return;
    }
    if (vale== "") {
      return;
    }
    
    app.util.request({
      url: 'admin/WxGoodsApi/searchClassify',
      data: {
        search_name: vale
      },
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res){
        that.setData({
          inputVal: vale,
          inputList:res.data.data
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: '搜索'
    })
    // 数据获取
    // console.log(wx.getStorageSync('historyInputVal'));
    var inputHis = wx.getStorageSync('historyInputVal')
    this.setData({
      historyInpVal: inputHis
    })
    
  },
  qingSure:function(){
    this.hideModal()
    // 数据清空
    wx.clearStorageSync(this.data.historyInpVal)
    this.onLoad()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})